<?php
class CookieTools {
	//域名设定
	private $domain = '.yufeikj.com';
	//共享项目路径
	private $path = '/';
	
	public function __construct(){
	    $args = func_get_args();
	    if(is_array($args) && count($args)==2){
	        $this->domain = $args[0];
	        $this->path = $args[1];
	    }
	}

	/**
	 * cookie跨域P3P协议设置
	 */
	public function cookieCrossDomain() {
		header('P3P: CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"');//p3p
	}

	/**
	 * 设置cookie
	 * @param string $cookieName
	 * @param string $cookieValue
	 * @param long $expireTime
	 */
	public function setCookie($cookieName, $cookieValue, $expireTime) {
	    try {
	    	if($expireTime==0)
	    		setcookie($cookieName, $cookieValue, 0, $this->path);
	    	else
	    		setcookie($cookieName, $cookieValue, time()+$expireTime, $this->path);
	    } catch (\Exception $e) {
	       ChromePhp::error($e->getMessage());  
	    }
	}

	/**
	 * 取得特定名的cookie值
	 * @param string $cookieName
	 * @return string
	 */
	public function getCookie($cookieName) {
		if (isset($_COOKIE[$cookieName]))
			return $_COOKIE[$cookieName];
		else
			return '';
	}
}

?>